import http from "@/http";

export const userListAPI = (
  params: IUserListParams
): RES<ITableResult<IList>> => http.get("/admin/list", { params });

export const userStatusAPI = (id: number, status: number): RES<number> =>
  http.post(`/admin/updateStatus/${id}?status=${status}`);

export const addUserAPI = (params: IList): RES<IList> =>
  http.post("/admin/register", params);

export const getUserByIdAPI = (id: number): RES<IList> =>
  http.get(`/admin/${id}`);

export const upDateUserAPI = (params: IList): RES<number> =>
  http.post(`admin/update/${params.id}`, params);

export const getRoleListAPI = (): RES<IRoleModel[]> =>
  http.get("/role/listAll");

export const getRolesByUserIdAPI = (adminId: number): RES<IRoleModel[]> =>
  http.get(`/admin/role/${adminId}`);

export const updateUserRolesAPI = (
  adminId: number,
  roleIds: number[]
): RES<number> =>
  http.post(
    `admin/role/update?adminId=${adminId}&roleIds=${roleIds.join(",")}`
  );

export const getRolePageAPI = (
  params: IUserListParams
): RES<IRoleListModel<IRoleList>> => http.get("/role/list", { params });

export const roleUpdateStatusAPI = (id: number, status: number): RES<number> =>
  http.post(`/role/updateStatus/${id}?status=${status}`);

export const cerateRoleAPI = (params: IRoleList): RES<IRoleList> =>
  http.post("/role/create", params);

export const editRolesAPI = (id: number, params: IRoleList): RES<number> =>
  http.post(`/role/update/${id}`, params);

export const getResourceListByRoleIdAPI = (
  roleId: number
): RES<IResourceModel[]> => http.get(`/role/listResource/${roleId}`);

export const resourceListAllAPI = (): RES<IResourceModel[]> =>
  http.get("/resource/listAll");

export const resourceCategoryAllAPI = (): RES<IResourceCategoryModel[]> =>
  http.get("/resourceCategory/listAll");

export const allocResource = (params: IAllocResourcePramas) =>
  http.post(
    `/role/allocResource?roleId=${
      params.roleId
    }&&resourceIds=${params.resourceIds.join(",")}`
  );
// /menu/treeList  树形结构返回所有菜单列表
export const ApiTreeList = (): RES<ITreeList[]> => http.get("/menu/treeList");
// /role/listMenu/{roleId} 获取角色相关菜单
export const ApiRoleList = (roleId: number): RES<IRoleMenuList[]> =>
  http.get(`/role/listMenu/${roleId}`);
// /role/allocMenu 给角色分配菜单
export const ApiAllocMenu = (params: IAllocMenuParams): RES<number> =>
  http.post(
    `/role/allocMenu?roleId=${params.roleId}&menuIds=${params.menuIds.join(
      ","
    )}`
  );

// 菜单列表的数据
export const getUmsMenuInfoAPI = (
  parentId: number,
  params?: IUserListParams
): RES<ITableResult<IMenuListModel>> =>
  http.get(`/menu/list/${parentId}`, { params });

// 菜单列表数据是否显示
export const menuUpdateHidden = (id: number, hidden: number): RES<number> =>
  http.post(`/menu/updateHidden/${id}?hidden=${hidden}`);

// 添加菜单
export const addMenuParamsAPI = (
  umsMenu: IMenuListModel
): RES<IMenuListModel> => http.post("/menu/create", umsMenu);

// 获取菜单就数据
export const getEditMenuParamsAPI = (id: number): RES<IMenuListModel> =>
  http.get(`menu/${id}`);

// 修改菜单
export const editMenuAPI = (id: number, params: IMenuListModel): RES<any> =>
  http.post(`/menu/update/${id}`, params);

// 资源列表的数据
export const getResourceListAPI = (
  params: IUserListParams
): RES<IRoleListModel<IResourceModel>> =>
  http.get(
    `/resource/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}`
  );
